<template>
  <div class="container">
    <FormData
      @handleQuery="search"
      @registerDispose="handleExport"
      :buttonName="'物品导出'"
    ></FormData>
    <div>
      <el-table
        v-loading="loading"
        ref="multipleTable"
        :data="list"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column align="center" type="selection"> </el-table-column>
        <el-table-column align="center" type="index" label="序号"> </el-table-column>
        <el-table-column align="center" prop="count" label="数量"> </el-table-column>
        <el-table-column align="center" prop="phName" label="人员"></el-table-column>
        <el-table-column align="center" prop="createTime" label="时间">
          <template slot-scope="scope">
            {{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作">
          <template slot-scope="scope">
            <el-button type="primary" size="small" @click="amend(scope.row.id)">下载</el-button>
            <el-button type="danger" size="small" @click="delW = true">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <Pagination
      class="page-container"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="pageGetList"
    ></Pagination>
    <!-- 删除弹框 -->
    <el-dialog title="提示" :visible.sync="delW" width="30%">
      <span>确定删除吗?</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="delW = false">取 消</el-button>
        <el-button type="primary" @click="removeW">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import FormData from '@/components/FormData'
import { getList } from '@/api/property/putRecord'
export default {
  components: {
    FormData
  },
  data() {
    return {
      // 数据
      list: [],
      // 选择数据
      multipleSelection: [],
      loading: false,
      // 数据条数
      total: 0,
      // 分页查询
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      delW: false
    }
  },
  methods: {
    search(queryForm) {
      this.loadList(queryForm)
    },
    // 获取数据
    loadList(queryForm = null) {
      // ${process.env.VUE_APP_BASE_API}
      // if (queryForm && queryForm.wId) queryForm.wIds = queryForm.wId
      this.loading = true
      getList(queryForm).then((res) => {
        res.rows.forEach((item) => {
          if (item.type) {
            switch (item.type) {
              case '1':
                item.type = '普通物品'
                break
              case '2':
                item.type = '特殊物品'
                break
              case '3':
                item.type = '车辆'
                break
            }
            // if (item.storeImg || item.deliverImg) {
            //   item.storeImg = `${process.env.VUE_APP_BASE_API}${item.storeImg}`
            //   item.deliverImg = `${process.env.VUE_APP_BASE_API}${item.deliverImg}`
            //   console.log(item.storeImg)
            // }
          }
        })
        this.list = [...res.rows]
        this.total = res.total
        this.loading = false
      })
    },
    // 分页查询
    pageGetList() {
      getList(this.queryParams).then((response) => {
        this.list = response.rows
        this.total = response.total
      })
    },
    // 导出事件
    handleExport() {
      this.download('financial/info/exportAll', {}, `disposal_${new Date().getTime()}.xlsx`)
    },
    // 删除
    removeW() {},
    toggleSelection(rows) {
      if (rows) {
        rows.forEach((row) => {
          this.$refs.multipleTable.toggleRowSelection(row)
        })
      } else {
        this.$refs.multipleTable.clearSelection()
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    }
  },
  created() {
    // 初始化数据
    this.loadList()
  }
}
</script>

<style scoped>
.container {
  padding: 15px;
}
</style>
